package collector

import (
	"encoding/json"
	"strconv"
	"strings"
)

type AMQMetric struct {
	Group     string
	Count     string
	Version   string
	Type      string
	Model     string
	TPS       string
	DiffTotal string
}

// 转换为json
func (m *AMQMetric) String() string {
	dj, _ := json.Marshal(m)
	return string(dj)
}

// 定一个数组接受AMQMetric
type AMQMetricSet struct {
	itmes []*AMQMetric
}

// 调用这个函数进行追加AMQMetricSet
func (s *AMQMetricSet) Add(m *AMQMetric) {
	s.itmes = append(s.itmes, m)
}

// 读取文件
func ParseLen(line string) *AMQMetric {
	fields := strings.Fields(line)
	// fmt.Printf("%v\n", fields)
	return &AMQMetric{
		Group:     fields[0],
		Count:     fields[1],
		Version:   fields[2],
		Type:      fields[3],
		Model:     fields[4],
		TPS:       fields[5],
		DiffTotal: fields[6],
	}
}

func (m *AMQMetric) IntCount() float64 {
	i, _ := strconv.ParseFloat(m.Count, 64)
	return i
}

func (m *AMQMetric) IntTPS() float64 {
	i, _ := strconv.ParseFloat(m.TPS, 64)
	return i
}

func (m *AMQMetric) IntDiffTotal() float64 {
	i, _ := strconv.ParseFloat(m.DiffTotal, 64)
	return i
}
